﻿using SqlSugar;
using System;

namespace DeHeng_Mes.Utils {
    class SqlSugarConfig {

       private static String server = EncryptOrDecrypt.Instance.Decrypt(SettingsManager.Instance.GetSetting("DBServer"));
       private static String port = EncryptOrDecrypt.Instance.Decrypt(SettingsManager.Instance.GetSetting("DBPort"));
       private static String dataBase = EncryptOrDecrypt.Instance.Decrypt(SettingsManager.Instance.GetSetting("DBDataBase"));

       private static string cpuId = MappingTable.DeviceIdentifier();
        private static (string, string) user = MappingTable.GetMySqlUser(cpuId);

        //组合连接字符串
       private static String connectionString = $"server={server ?? "127.0.0.1"};user id={"root"};password={"123456"};database={ dataBase ?? "jiabenf2-line"};Port={ port ??"3306"};Pooling=true;Max Pool Size=100;";
       private static String connectionString1 = $"server={server ?? "127.0.0.1"};user id={"root"};password={"123456"};database={ dataBase ?? "jiabenf2-line2"};Port={ port ??"3306"};Pooling=true;Max Pool Size=100;";
       private static String connectionString2 = $"server={server ?? "127.0.0.1"};user id={"root"};password={"123456"};database={ dataBase ?? "weber_schraubautomaten_c50rsf"};Port={ port ??"3306"};Pooling=true;Max Pool Size=100;";
        /// <summary>
        /// ORM框架 SQLSugar 使用时尽量用 using 包裹代码块 以确保资源被释放不浪费
        /// </summary>
        public static SqlSugarClient Db => new SqlSugarClient(new ConnectionConfig() {
            ConnectionString = connectionString, // 替换为你的数据库连接字符串  
            DbType = DbType.MySql, // 根据你的数据库类型设置  
            IsAutoCloseConnection = true, // 自动释放数据务，如果存在事务，在事务结束后释放  
            InitKeyType = InitKeyType.Attribute // 从实体特性中获取主键和自增列信息  
            // 其他配置...  
        });
        public static SqlSugarClient fdsDb => new SqlSugarClient(new ConnectionConfig()
        {
            ConnectionString = connectionString2, // 替换为你的数据库连接字符串  
            DbType = DbType.MySql, // 根据你的数据库类型设置  
            IsAutoCloseConnection = true, // 自动释放数据务，如果存在事务，在事务结束后释放  
            InitKeyType = InitKeyType.Attribute // 从实体特性中获取主键和自增列信息  
            // 其他配置...  
        });
    }
}
